<!-- 管理员：修改密码 -->
<template>
    <div class="vue-box submit-box--dialog">
        <div class="c-card" style="width: 500px;">
            <el-form :inline="false" label-width="10em" v-if="state.model">
                <in-input type="password" name="旧密码：" v-model="state.model.oldPassword"></in-input>
                <in-input type="password" name="再次输入旧密码：" v-model="state.model.oldPassword2"></in-input>
                <in-input type="password" name="新密码：" v-model="state.model.newPassword"></in-input>
                <in-input type="password" name="再次输入新密码：" v-model="state.model.newPassword2"></in-input>
            </el-form>
        </div>
    </div>
</template>

<script setup name="update-password">
import {reactive} from "vue";
import InInput from "../../sa-frame/com/in/in-input";
import md5 from 'md5'
import { useUserStore } from "../../store/user";

// ------------------ 数据 ------------------
const state = reactive({
    model: {    // 数据 Model
        oldPassword: '',
        oldPassword2: '',
        newPassword: '',
        newPassword2: ''
    }
});
const userInfo = useUserStore().userInfo

// ------------------ 函数 ------------------
// 提交表单 
const ok = function () {
    // 表单校验
    let model = state.model;
    sa.checkNull(model.oldPassword && model.oldPassword2 && model.newPassword && model.newPassword2, '请填写');
    sa.check(model.oldPassword !== model.oldPassword2, '旧密码两次输入不一致');
    sa.check(model.newPassword !== model.newPassword2, '新密码两次输入不一致');
    sa.check(model.newPassword.length < 4, '新密码请不要低于六位数');
    // 开始修改 
    const params = {
        oldPassword: md5(state.model.oldPassword),
        newPassword: md5(state.model.newPassword),
        fixmedins_code: userInfo.fixmedins_code
    }
    sa.ajax('/api/webPresAdmin/changePassword', params, function() {
        sa.closeModel();
        sa.msg('修改成功！');
    })
}

// 对外开放函数 
defineExpose({
    ok: ok
});


</script>

<style scoped>

</style>
